package com.spica.platform.user.exception;

import com.spica.platform.base.exception.errorcode.IErrorCode;
import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum SysRoleRtnCodEnum implements IErrorCode {
    UN_KNOWN_SYS_ERROR("UN_KNOW_SYS_ERROR", "未知异常"),
    SYS_ROLE_00001("SYS_ROLE_00001", "后台管理保存更新角色操作失败"),
    SYS_ROLE_00002("SYS_ROLE_00002", "后台管理保存更新角色操作成功"),
    SYS_ROLE_00003("SYS_ROLE_00003", "后台管理删除角色操作失败"),
    SYS_ROLE_00004("SYS_ROLE_00004", "后台管理删除角色操作成功"),
    ;

    String rtnCod;
    String rtnMsg;
    SysRoleRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    }

    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(SysRoleRtnCodEnum.values())
                .filter(sysRoleRtnCodEnum -> StringUtil.equals(sysRoleRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(SysRoleRtnCodEnum.UN_KNOWN_SYS_ERROR);
    }
}
